﻿using Logic;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace web_CategoryMS.View.G01
{
    public partial class FS0104 : System.Web.UI.Page
    {
        FS0104Logic fS0104Logic = new FS0104Logic();
        #region 初始化事件
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        #endregion

        #region 检索方法
        private void Search()
        {
            DataTable dt = fS0104Logic.Search(txtOrderID.Text.Trim());
            if (dt!=null && dt.Rows.Count>0)
            {
                dgv.DataSource = dt;
                dgv.DataBind();
            }
            else
            {
                BindNullDT();
            }
        }
        #endregion

        #region 绑定空行
        private void BindNullDT()
        {
            DataTable dt = new DataTable();
            dt.Rows.Clear();
            dt.Columns.Add("iAutoID");
            dt.Columns.Add("vcProjectNo");
            dt.Columns.Add("vcOrderID");
            dt.Columns.Add("vcRequirementID");
            dt.Columns.Add("vcRequirementNo");
            dt.Columns.Add("vcRequirementName");
            dt.Columns.Add("vcRequirementDescription");
            dt.Columns.Add("vcRequirementContent");
            dt.Columns.Add("vcCreateID");
            DataRow dr = dt.NewRow();
            dr["iAutoID"] = "";
            dr["vcProjectNo"] = "";
            dr["vcOrderID"] = "";
            dr["vcRequirementID"] = "";
            dr["vcRequirementNo"] = "";
            dr["vcRequirementName"] = "";
            dr["vcRequirementDescription"] = "";
            dr["vcRequirementContent"] = "";
            dr["vcCreateID"] = "";
            dt.Rows.Add(dr);
            dgv.DataSource = dt;
            dgv.DataBind();
        }
        #endregion

        #region 行绑定事件
        protected void dgv_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            try
            {
                if (e.Row.RowType == DataControlRowType.DataRow)
                {
                    if (string.IsNullOrEmpty(e.Row.Cells[1].Text) || e.Row.Cells[1].Text == "&nbsp;")
                    {
                        return;
                    }
                    e.Row.Cells[6].Attributes.Add("onclick", "return OpenImage('" + e.Row.Cells[4].Text + "');");
                }
            }
            catch (Exception ex)
            {

            }
        }
        #endregion

        #region 检索事件
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            try
            {
                Search();
            }
            catch (Exception ex)
            {

            }
        }
        #endregion

        #region 全选事件
        protected void btnAll_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (GridViewRow gvr in dgv.Rows)
                {
                    ((CheckBox)gvr.Cells[0].FindControl("ChkItem")).Checked = true;
                }
            }
            catch (Exception ex)
            {

            }
        }
        #endregion

        #region 删除事件
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                #region 获取选中的项
                List<string> Items = new List<string>();
                foreach (GridViewRow gvr in dgv.Rows)
                {
                    if (((CheckBox)gvr.Cells[0].FindControl("ChkItem")).Checked)
                    {
                        string iAutoID = gvr.Cells[1].Text;
                        if (!string.IsNullOrEmpty(iAutoID))
                        {
                            Items.Add(iAutoID);
                        }
                    }
                }
                #endregion

                fS0104Logic.Delete(Items);

                Search();

                ScriptManager.RegisterStartupScript(this, typeof(Page), "", "alert('删除成功！');", true);

            }
            catch (Exception ex)
            {
            }
        }
        #endregion
    }
}